<?php 
/**
 * CodeIgniter-Tokaban framework for PHP
 *
 * @package		Tokaban_standard_system
 * @author		Tokaban R&D Team
 * @copyright	Copyright (c) 2009, Tokaban, Inc.
 * @license		http://tokaban.com/tkb_php_code/TkbPbp_license.html
 * @link		http://tokaban.com
 * @since		Version 1.1
 *
 * @test code	
 * @tester		an_hm87 - 01/08/2009
 *
 * ----------------------------------------------------------------
*/
class check_system_hooks
{  
  
/**
* Constructor
*/   

public function __construct() 
	{ 
	  $this->obj =& get_instance(); 
	  $this->obj->load->helper('ap_function'); 
	} 
  
/**
*
* Kiem tra dieu kien hop le de truy xuat cac controller backend.
* Neu bien nay chua duoc khoi tao, he thong se yeu cau khoi tao lai do_init.
* 
* @author	: an_hm87.
*/
public function check_system_valid()
	{
		switch ( trim($this->obj->tokaban_system_check) )
		{			
			// Only use for init controller.
			case 'begin':
				return TRUE;
				break;
			
			// Check valid begin from init controller	
			case '0':
				if ( $this->check_begin_application_valid() == TRUE )
					return TRUE;
				else
					redirect ('do_init');	
				break;
			
			// Check valid BackEnd.	
			case '1': 
				if ( $this->check_valid_backend())
					return TRUE;
				else
					redirect ('do_init');	
				break;
			
			// Check valid FrontEnd.	
			case '2':			
				if ( $this->check_valid_frontend() == TRUE )
					return TRUE;
				else
					redirect ('do_init');	
				break;			
			// Invalid run application.				
			default:
				exit('Your code invalid. <br> Check it with your R&D team, please.');
				break;			
		}		
	}

//
//	Kiem tra ung dung duoc khoi dong hop le.
//
private function check_begin_application_valid()
    {
		if (Fget_userdata('session_begin_application')=='1')
			return TRUE;
		else
			return FALSE;
									
    }

//
//	Kiem tra dieu kien su dung cac controller thuoc backend.
//
private function check_valid_frontend()
    {
		if($this->check_begin_application_valid() == TRUE)
			return TRUE;
		else
			return FALSE;	
    }

//
//	Kiem tra dieu kien su dung cac controller thuoc backend.
//
function  check_login()
{	
	
			if(Fget_userdata('session_nid_user') =='' OR Fget_userdata('session_nid_user') =='0')
				return FALSE;
			else
				return TRUE;

}
private function check_valid_backend()
    {	
		if($this->check_begin_application_valid() == TRUE AND $this->check_login()== TRUE)
			return TRUE;
		else
			return FALSE;
    }
}

